var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s,
    c,
    l = e("Util"),
    d = e("WechatExportManager"),
    u = e("AdItem"),
    p = cc._decorator,
    h = p.ccclass,
    f = p.property;
((c = s || (s = {}))[(c.None = 0)] = "None"),
    (c[(c.Top = 1)] = "Top"),
    (c[(c.Bottom = 2)] = "Bottom"),
    (c[(c.Left = 3)] = "Left"),
    (c[(c.Right = 4)] = "Right");
var _ = (function (e) {
    function t() {
        var t = (null !== e && e.apply(this, arguments)) || this;
        return (
            (t.scrollView = null),
            (t.node_content = null),
            (t.node_item = null),
            (t.node_display_region = null),
            (t.node_btn_continue = null),
            (t._showGameList = []),
            (t._adList = []),
            (t._moveDir = s.None),
            t
        );
    }
    return (
        a(t, e),
        (t.prototype.start = function () {
            var e = this;
            for (
                this.addEvent(),
                    cc.winSize.width > cc.winSize.height
                        ? ((this.node_content.anchorX = 0),
                          (this.node_content.anchorY = 0.5),
                          (this.node_content.getComponent(cc.Layout).startAxis = cc.Layout.AxisDirection.VERTICAL),
                          (this.scrollView.horizontal = !0),
                          (this._moveDir = s.Left))
                        : cc.winSize.width < cc.winSize.height &&
                          ((this.node_content.anchorX = 0.5),
                          (this.node_content.anchorY = 1),
                          (this.node_content.getComponent(cc.Layout).startAxis = cc.Layout.AxisDirection.HORIZONTAL),
                          (this.scrollView.vertical = !0),
                          (this._moveDir = s.Top)),
                    this.node_content.getComponent(cc.Widget).updateAlignment();
                this._showGameList.length < 50 && d.default.instance.gameList.length > 0;

            )
                this._showGameList = this._showGameList.concat(d.default.instance.gameList);
            l.default.shuffle(this._showGameList);
            for (var t = this.node_item.getContentSize(), o = 0; o < Math.min(150, this._showGameList.length); o++) {
                var n = this._showGameList[o];
                if (!n) break;
                var i = new cc.Node();
                i.setContentSize(t);
                var a = cc.instantiate(this.node_item);
                (a.position = cc.Vec3.ZERO),
                    a.getComponent(u.default).setData(n),
                    i.addChild(a),
                    this.node_content.addChild(i),
                    this._adList.push(a),
                    this.scheduleOnce(function () {
                        e.checkDisplay();
                    });
            }
        }),
        (t.prototype.addEvent = function () {
            this.node_btn_continue.on("click", this.onClickContinue, this);
        }),
        (t.prototype.update = function (e) {
            this._moveDir === s.Top
                ? ((this.node_content.y += 90 * e),
                  this.node_content.y > this.node_content.height - this.scrollView.node.height / 2 &&
                      (this._moveDir = s.Bottom))
                : this._moveDir === s.Bottom
                ? ((this.node_content.y -= 90 * e),
                  this.node_content.y < this.scrollView.node.height / 2 && (this._moveDir = s.Top))
                : this._moveDir === s.Left
                ? ((this.node_content.x -= 90 * e),
                  this.node_content.x <
                      0 - this.scrollView.node.width / 2 - (this.node_content.width - this.scrollView.node.width) &&
                      (this._moveDir = s.Right))
                : this._moveDir === s.Right &&
                  ((this.node_content.x += 90 * e),
                  this.node_content.x > 0 - this.scrollView.node.width / 2 && (this._moveDir = s.Left)),
                this.checkDisplay();
        }),
        (t.prototype.checkDisplay = function () {
            var e = this.node_display_region.getBoundingBoxToWorld();
            this._adList.forEach(function (t) {
                var o = t.getBoundingBoxToWorld();
                e.intersects(o) ? (t.active = !0) : (t.active = !1);
            });
        }),
        (t.prototype.onClickContinue = function () {
            this.node.destroy();
        }),
        r([f(cc.ScrollView)], t.prototype, "scrollView", void 0),
        r([f(cc.Node)], t.prototype, "node_content", void 0),
        r([f(cc.Node)], t.prototype, "node_item", void 0),
        r([f(cc.Node)], t.prototype, "node_display_region", void 0),
        r([f(cc.Node)], t.prototype, "node_btn_continue", void 0),
        r([h], t)
    );
})(cc.Component);
i.default = _;
